package com.ff.discounts.component.addressdetail

import android.view.Menu
import android.view.MenuItem
import android.widget.TextView
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import com.ff.discounts.R
import com.ff.discounts.activity.BaseTitleActivity
import com.ff.discounts.component.address.NewAreaData
import com.ff.discounts.databinding.ActivityAddressDetailBinding
import com.ff.discounts.library.log.HiLog
import com.ff.discounts.util.Constant
import kotlinx.coroutines.launch


/**
 * 收货地址详情
 */
class AddressDetailActivity : BaseTitleActivity<ActivityAddressDetailBinding>() {
    private lateinit var viewModel: AddressDetailViewModel

    /**
     * 返回菜单
     */
    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menuInflater.inflate(R.menu.menu_address_detail, menu)
        return super.onCreateOptionsMenu(menu)
    }

    /**
     * 菜单点击事件
     */
    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        when (item.itemId) {
            R.id.save -> {

            }
        }
        return super.onOptionsItemSelected(item)
    }

    override fun initDatum() {
        super.initDatum()

        // 创建ViewModel
        val addressDetailViewModelFactory =
            AddressDetailViewModelFactory(intent.getStringExtra(Constant.ID))
        viewModel = ViewModelProvider(
            this,
            addressDetailViewModelFactory
        )[AddressDetailViewModel::class.java]
        initViewModel(viewModel)
        viewModel.loadData()

        lifecycleScope.launch {
            viewModel.areaData
                .collect { data ->

                }
        }
    }

    override fun initListeners() {
        super.initListeners()
        // 地区点击
        binding.area.setOnClickListener {
          HiLog.d("显示省市区三级选择")
        }
    }





}